import { createApp } from 'vue'
import App from './App.vue'
let app = createApp(App)
import 'element-plus/theme-chalk/index.css'
import router from './router/index.js'
import pinia from './store'

import { createI18n } from "vue-i18n";
import ZH from './language/zh'
import EN from './language/en'
const i18n = createI18n({
    legacy: false,
    locale: localStorage.getItem("language") || 'zh',
    globalInjection: true,
    messages: {
        zh: {
            text: ZH
        },
        en: {
            text: EN
        }
    }
});

import { useNet } from './store/net'
let net = useNet()
router.beforeEach((to, from, next) => {   //路由切换检测是否强行中断，
    if (net.cancel) {        //强行中断时才向下执行
        net.cancel('interrupt');   //给个标志，中断请求
    }
    next();
});


//解决ResizeObserver loop limit exceeded的问题
const debounce = (fn, delay, ...value) => {
    let timer = null;
    return () => {
        let context = this;
        let args = value;
        clearTimeout(timer);
        timer = setTimeout(function () {
            fn.apply(context, args);
        }, delay);
    };
};
const _ResizeObserver = window.ResizeObserver;
window.ResizeObserver = class ResizeObserver extends _ResizeObserver {
    constructor(callback) {
        callback = debounce(callback, 16);
        super(callback);
    }
};


app.use(router).use(pinia).use(i18n).mount('#app')
